<template>
  <div class="song">
    <div class="j-flag">
      <loading v-if="loading_flag"></loading>
      <!-- 整个歌单的头部 图片 介绍 标签.... -->
      <div class="g-wrap"  v-if="songdata"> 
        <div class="cover u-cover u-cover-dj">
          <img :src="songdata.coverImgUrl" />
          <span class="msk"></span>
        </div>
        <div class="cnt">
          <div class="cntc m-info">
            <div class="hd f-cb">
              <i class="type u-icn u-icn-13 f-pr">
                <span
                  class="f-pa f-r-white-icon"
                  style="
                    display: inline-block;
                    width: 8px;
                    height: 8px;
                    top: 2px;
                    background-size: cover;
                    left: 34px;
                  "
                ></span>
              </i>
              <h2 class="f-ff2 f-thide">{{ songdata.name }}</h2>
            </div>
            <div class="user f-cb">
              <a class="face" href="/javascript:;">
                <img :src="songdata.creator.avatarUrl" />
              </a>
              <span class="name f-thide">
                <a
                  href="javascript:;"
                  class="s-fc7"
                  title="撞它撞它"
                  v-text="songdata.creator.nickname"
                ></a>
              </span>
              <span class="time s-fc4"
                >{{ songdata.createTime | FormatDate }}&nbsp;创建</span
              >
            </div>
            <div class="btns f-cb">
              <a href="javascript:;" class="u-btn2 u-btn2-2 u-btni-addply f-fl" @click="playAll">
                <i><em class="ply"></em>播放</i>
              </a>
              <a
                href="javascript:void(0)"
                class="u-btni u-btni-fav u-btni-fav-dis"
              >
                <i class="bp">收藏</i>
              </a>
              <a
                href="javascript:void(0)"
                class="u-btni u-btni-fav u-btni-fav-dis"
              >
                <i class="bp1">({{ songdata.shareCount }})</i>
              </a>
              <a
                href="javascript:;"
                class="u-btni u-btni-fav u-btni-fav-dis"
              >
                <i class="bp2">({{ songdata.commentCount }})</i>
              </a>
            </div>
            <div class="tags f-cb" v-if="songdata.tags.length">
              <b>标签：</b>
              <a
                class="u-tag"
                href="Javascript:;"
                v-for="(item, index) in songdata.tags"
                :key="index"
              >
                <i>{{ item }}</i>
              </a>
            </div>
            <div class="intr f-brk" v-if="songdata.description">
              <b>介绍：</b>
              {{ songdata.description }}
            </div>
          </div>
        </div>
      </div>
      <!-- 歌曲列表头部 -->
      <div class="u-title u-title-1" v-if="songdata">
        <h3>
          <span class="f-ff2">歌曲列表</span>
        </h3>
        <span class="sub s-fc3">
          <span>{{ songdata.trackCount }}</span>
          首歌
        </span>
        <div class="more s-fc3">
          播放：<strong id="flag_playCount" class="s-fc6">470117</strong> 次
        </div>
      </div>
    </div>
    <!-- 歌曲列表 -->
    <playlist :listdata="songdata.tracks" v-if="songdata"></playlist>
    <!-- 评论 -->
    <comment :id="commentIDS" v-if="songdata"></comment>
  </div>
</template>

<script>
import playlist from "./playlist";
import comment from "../../../components/comment/comment";
import loading from '../../../components/Loading/Loading.vue'
import { formatDate } from "../../../components/tool/tool";
import { playlist_detail } from "../../../network/login";
import Login from '../../../components/loging_box/login.vue';
export default {
  props: ["id"],
  data() {
    return {
      song_id: "", //歌单id
      songdata:null,//歌单数据
      loading_flag:true, //加载图标
      filteraPlaylistData:[], //过滤后这个歌单可以播放的歌曲
      commentIDS:null,
    };
  },
  components: {
     playlist,
    comment,
     loading
  },
  methods: {
    res(id) {
      playlist_detail(id).then((res) => {
          this.songdata = res.data.playlist;
          this.filterplaylist(res.data.playlist.tracks )
           this.$nextTick(() => {
              if(this.songdata){
                 this.loading_flag = false
              }
           })
        },
        (err) => {
          console.log("创建歌单->我喜欢->详情 错误");
        } 
      );
    },
    filterplaylist(arr){
       this.filteraPlaylistData = []
        arr.forEach(item => {
            if ((parseInt(item.fee) < 1 || parseInt(item.fee) > 4 ) && !item.noCopyrightRcmd) {
                  this.filteraPlaylistData.push(item)
             }
        });
    },
    playAll(){
        if(this.filteraPlaylistData.length){
            var song_ids = {
                    name: '歌单',
                    ids: this.filteraPlaylistData,
                    song_id: this.songdata.id,
               }
           this.$store.commit("songAll_ids" , song_ids)
          }
    }
  },
  filters: {
    FormatDate(v) {
      const date = formatDate(v);
      return date;
    },
  },
  watch:{
     $route(to){
      this.res(to.query.id);
      this.song_id = to.query.id
      this.commentIDS = { name: "歌单", id:to.query.id}; 
     },
     "$store.state.subMusic":function(data){
        if(data && parseInt(data.playlistId) == this.song_id){
            this.songdata.tracks.unshift(data.subMS)
        }
     }
  },
  created() {
    this.res(this.$route.query.id);
    this.song_id = this.$route.query.id
    this.commentIDS = { name: "歌单", id:this.$route.query.id};
   },
};
</script>
<style scoped>
.song {
  position: relative;
  padding-bottom: 40px;
}
.g-wrap {
  padding: 40px;
  overflow: auto;
}
.cover {
  float: left;
  position: relative;
  display: inline;
  margin: 0 -220px 0 0;
}
.u-cover-dj {
  width: 200px;
  height: 200px;
}
.u-cover img {
  display: block;
  width: 100%;
  height: 100%;
}
.u-cover-dj .msk {
  width: 208px;
  height: 208px;
  background-position: 0 -1285px;
  top: -4px;
  left: -4px;
}
.u-cover .msk {
  position: absolute;
}
.g-wrap .cnt {
  float: right;
  width: 100%;
}
.g-wrap .cntc {
  margin-left: 230px;
}
.g-wrap .hd {
  position: relative;
  margin: 0 0 12px;
  line-height: 24px;
}
.g-wrap .hd .type {
  position: relative;
  top: 3px;
}
.g-wrap .type {
  float: left;
  margin-right: 6px;
}
.u-icn {
  display: inline-block;
  overflow: hidden;
  vertical-align: middle;
  background: url("../../../assets/imgs/icon.png") no-repeat;
}
.u-icn-13 {
  width: 54px;
  height: 24px;
  background-position: 0 -243px;
}
i {
  font-style: normal;
  text-align: left;
  font-size: inherit;
}
h2,
h3 {
  margin: 0;
  padding: 0;
}
.m-info .hd h2 {
  line-height: 24px;
  font-size: 20px;
  font-weight: normal;
}
.f-thide {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-wrap: normal;
}
.f-ff2 {
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
}
.cnt .user {
  margin: 0 0 20px;
  line-height: 35px;
}
.m-info .user .face {
  margin-right: 10px;
  float: left;
  width: 35px;
  height: 35px;
}
a {
  text-decoration: none;
  color: #333;
}
.m-info .user .face img {
  float: left;
  width: 35px;
  height: 35px;
}
.m-info .user .name {
  max-width: 210px;
  float: left;
}
.s-fc7 {
  color: #0c73c2;
  font-size: 12px;
}
.m-info .user .time {
  margin-left: 15px;
}
.s-fc4 {
  color: #999;
  font-size: 12px;
}
.m-info .btns {
  margin-bottom: 25px;
  margin-right: -10px;
}
.u-btn2 {
  padding: 0 5px 0 0;
  white-space: nowrap;
  display: inline-block;
  height: 31px;
  line-height: 31px;
  overflow: hidden;
  vertical-align: top;
  text-align: center;
  cursor: pointer;
}
.u-btni-addply {
  float: left;
}
.u-btn2-2 {
  color: #fff;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
  background-position: right -428px;
}
.u-btni-addply i {
  padding: 0 7px 0 8px;
}
.u-btn2-2 i {
  color: #fff;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
  background-position: 0 -387px;
}
.u-btn2,
.u-btn2 i {
  display: inline-block;
  height: 31px;
  line-height: 31px;
  overflow: hidden;
  vertical-align: top;
  text-align: center;
  cursor: pointer;
}
.u-btni-addply .ply {
  float: left;
  width: 20px;
  height: 18px;
  margin: 6px 2px 2px 0;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
  background-position: 0 -1622px;
  overflow: hidden;
}
em,
i {
  font-style: normal;
  text-align: left;
  font-size: inherit;
  font-size: 12px;
}
.m-info .btns .u-btni {
  margin-right: 6px;
  font-family: simsun, \5b8b\4f53;
  color: #333;
  padding: 0 5px 0 0;
  white-space: nowrap;
  float: left;
  height: 31px;
  line-height: 30px;
  min-width: 23px;
  margin-left: 5px;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
}
.u-btni-fav-dis {
  cursor: default;
  background-position: right -1192px;
}
.u-btni i {
  float: left;
  height: 31px;
  line-height: 30px;
  min-width: 23px;
  padding: 0 7px 0 36px;
}
.u-btni-fav-dis i {
  color: #bebebe;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
  cursor: default;
}
.u-btni-fav-dis .bp {
  background-position: 0 -1149px;
}
.u-btni-fav-dis .bp1 {
  background-position: 0 -1225px;
  color: #333;
}
.u-btni-fav-dis .bp2 {
  background-position: 0 -1465px;
  color: #333;
}
.m-info .tags {
  margin: 25px 0 5px;
  line-height: 22px;
}
.m-info .tags b {
  float: left;
}
.m-info b {
  font-weight: normal;
  color: #666;
}
.m-info .tags .u-tag {
  float: left;
  margin: 0px 10px 3px 0;
}
.u-tag {
  padding: 0 10px 0 0;
  text-shadow: 0 1px #fdfdfd;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
  background-position: right -27px;
  color: #777;
  text-decoration: none;
  height: 22px;
  line-height: 22px;
}
.u-tag i {
  position: relative;
  zoom: 1;
  padding: 0 3px 0 13px;
  background-image: url("https://s2.music.126.net/style/web2/img/button2.png?a11a1b6a2966c30393ed8d8d55cbfea8");
  background-position: 0 0;
  float: left;
  height: 22px;
  line-height: 22px;
}
.f-cb:after {
  clear: both;
  content: ".";
  display: block;
  height: 0;
  visibility: hidden;
}
.m-info .intr {
  margin-top: 4px;
  line-height: 18px;
  color: #666;
  font-size: 12px;
}
.f-brk {
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}
.m-info .intr b {
  display: inline-block;
}
.m-info b {
  font-weight: normal;
  color: #666;
  font-size: 12px;
  font-family: Arial, Helvetica, sans-serif;
}
.u-title-1 {
  padding: 0 10px 0 32px;
  height: 33px;
}
.u-title {
  border-bottom: 2px solid #c20c0c;
}
.u-title-1 h3 {
  font-size: 20px;
  line-height: 28px;
}
.u-title h3 {
  float: left;
  font-weight: normal;
}
.f-ff2 {
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
}
.u-title-1 .sub {
  margin: 9px 0 0 20px;
  float: left;
}
.s-fc3 {
  color: #666;
  font-size: 12px;
}
.u-title-1 .more {
  margin-top: 5px;
  float: right;
}
.s-fc3 {
  color: #666;
}
</style>